package com.example.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.demo.common.R;
import com.example.demo.entity.dto.DoctorQueryDto;
import com.example.demo.entity.pojo.Doctor;
import com.example.demo.entity.vo.DoctorVo;
import com.example.demo.service.DoctorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author liye
 * @date 2025/10/9 14:31
 * @description:
 */
@RestController
@RequestMapping("/doctor")
@Tag(name = "医生管理")
public class DoctorController {

    @Resource
    private DoctorService doctorService;

    // 添加医生
    @PostMapping("/add")
    @Operation(summary = "添加医生")
    public R add(@RequestBody Doctor doctor) {
        boolean result = doctorService.save(doctor);
        return result ? R.success() : R.error();
    }

    // 更新医生
    @PutMapping("/update")
    @Operation(summary = "更新医生")
    public R update(@RequestBody Doctor doctor) {
        boolean result = doctorService.updateById(doctor);
        return result ? R.success() : R.error();
    }

    // 删除医生
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除医生")
    public R delete(@PathVariable("id") Integer doctorId) {
        boolean result = doctorService.removeById(doctorId);
        return result ? R.success() : R.error();
    }

    // 分页查询医生
    @GetMapping("/page")
    @Operation(summary = "分页查询医生")
    public R page(DoctorQueryDto queryDto) {
        IPage<DoctorVo> page = doctorService.page(queryDto);
        return R.success(page.getRecords(), page.getTotal());
    }
}
